/******************************************************************************
* 文件名称: msg_task.c
* 内容摘要: 消息处理任务
* 创建者の: 孔佳伟
* 个人主页: https://gitee.com/thin-wind/jump
* 修改记录: 
******************************************************************************/

#include "msg_task.h"
#include "msg_buf.h"
#include "id_reg.h"
#include "msg_log.h"
#include "msg_port.h"

IdReg_S     __id_reg_start__;
IdReg_S     __id_reg_end__;


void Msg1msTask(void)
{
    Msg_S msg = {0};
    IdReg_S *idReg = NULL;

    {static uint32_t cnt = 0; if(cnt < INTERVAL_TIMER) {cnt++; return;} cnt = 0;}

    // 以下每 INTERVAL_TIMER (ms) 执行一次
    
    if(0 == GetFromRxBuf(&msg))
    {
        for(idReg = &__id_reg_start__; idReg < &__id_reg_end__; idReg++)
        {
            if(idReg->id == msg.id)
            {
                if(NULL != idReg->func)
                {
                    idReg->func(msg.data, FRAME_SIZE);
                    break;
                }
            }
        }
        if(idReg == &__id_reg_end__)
            MSG_LOG("Invalid ID\n");
    }

    if(0 == GetFromTxBuf(&msg))
    {
        ll_write(&msg);
    }

}





